﻿using System.Collections.Generic;
using WebAPI.Dao;
using WebAPI.Entities;

namespace WebAPI.Services;

public class CommentService
{
    private CommentMapper _commentMapper = new CommentMapper();
    private TimeTransferUtils _transferUtils = new TimeTransferUtils();
    private IdGenerate _idGenerate = new IdGenerate();
    
    public List<Comment> GetAllComments(string article_id)
    {
        List<Comment> classifies = _commentMapper.SelectAll(article_id);
        
        return classifies;
    }

    public bool AddComment(Comment comment)
    {
        comment.Id = _idGenerate.GetId();
        
        comment.CreateTime = TimeTransferUtils.GetSqlServerTimeString();
        comment.UpdateTime = TimeTransferUtils.GetSqlServerTimeString();
        
        int flag = _commentMapper.Insert(comment);
        
        return flag > 0;
    }
    
    public bool UpdateComment(Comment comment)
    {
        comment.UpdateTime = TimeTransferUtils.GetSqlServerTimeString();
        int flag = _commentMapper.Update(comment);
        return flag > 0;
    }
    
    public bool DeleteComment(Comment comment)
    {
        int flag = _commentMapper.Delete(comment);
        
        return flag > 0;
    }
}